package cn.com.zpark;

import cn.com.zpark.dbcp.C3P0Utils01;
import cn.com.zpark.dbcp.C3P0Utils02;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @PackageName: cn.com.zpark
 * @ClassName: DBCP_01_Select
 * @Description:
 * @author: RZS
 * @date: 2021/10/31  16:52
 */
public class C3P0_02_Select {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement stat = null;
        ResultSet res = null;


        // 获取连接
        try {
            conn = C3P0Utils02.getConn();
            // 编写sql
            String sql = "select * from user";
            // 获取PreparedStatement对象
            stat = conn.prepareStatement(sql);
            // 替换占位符

            // 执行sql
            res = stat.executeQuery();

            // 遍历结果集
            while (res.next()) {
                int id = res.getInt("id");
                String name = res.getString("name");
                String pwd = res.getString("pwd");
                double money = res.getDouble("money");
                System.out.println(id + "--"+name+"--"+pwd+"--"+money);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            // 关闭连接
            C3P0Utils02.close(res, conn, stat);
        }

    }
}
